<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('申请标题')" prop="actTitle">
            <el-input v-model="form.actTitle" :placeholder="$t('申请标题')" show-word-limit :maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col v-if="!$route.query.id" :span="12">
          <el-form-item :label="$t('项目名称')" prop="dealId">
            <DealSelect
              v-model="form.dealId"
              :placeholder="$t('项目名称')"
              deal-status="TH"
              deal-type="equity"
              @change="dealSelectChangeHandle"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('注册资本') + $t('(万)') + '/' + $t('总股数') + $t('(万股)')" prop="registeredCapita">
            <Money v-model="form.registeredCapita" unit="w" :placeholder="$t('注册资本') + $t('(万)') + '/' + $t('总股数') + $t('(万股)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('币种')" prop="currency">
            <el-select v-model="form.currency" :placeholder="$t('币种')" @change="settingHoldShareCurrency">
              <el-option
                v-for="dict in currencyOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('退出状态')" prop="quitStatus">
            <dictSelect
              v-model="form.quitStatus"
              :clearable="true"
              dictionary="quit_status"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('回款类型')" prop="distributionType">
            <el-select v-model="form.distributionType" filterable :placeholder="$t('回款类型')">
              <el-option
                v-for="dict in distributionTypeOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('权益变更时间')" prop="distributionDate">
            <DatePicker v-model="form.distributionDate" :placeholder="$t('权益变更时间')" @change="getWebRate" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('相关退出决策')" prop="joinExit">
            <el-select v-model="form.joinExit" filterable :placeholder="$t('相关退出决策')" clearable>
              <el-option
                v-for="exit in exitList"
                :key="exit.id"
                :label="exitModeFormat(exit) + ' - ' + parseTime(exit.draftExitTime)"
                :value="exit.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('关联合同')" prop="relatedContracts">
            <el-select v-model="form.relatedContracts" clearable :placeholder="$t('关联合同')">
              <el-option
                v-for="(item, index) in contractOptions"
                :key="index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('本金') + $t('金额单位')" prop="amountPrincipal">
            <money v-model="form.amountPrincipal" disabled unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('收益') + $t('金额单位')" prop="amountIncome">
            <money v-model="form.amountIncome" disabled unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分红') + $t('金额单位')" prop="amountBonus">
            <money v-model="form.amountBonus" disabled unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('其它') + $t('金额单位')" prop="amountOthers">
            <money v-model="form.amountOthers" disabled unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('回款总额') + $t('金额单位')" prop="amountDistribution">
            <money v-model="form.amountDistribution" disabled unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('回款后持股数量') + $t('(万股)')" prop="numberOfShares">
            <money v-model="form.numberOfShares" unit="w" disabled :placeholder="$t('回款后持股数量')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('回款后持股比例(%)')" prop="exitShareRatio">
            <Ratio v-model="form.exitShareRatio" disabled :controls="false" :placeholder="$t('回款后持股比例(%)')" :precision="2" :max="100" :min="0" />
          </el-form-item>
        </el-col>
        <el-col
          v-for="(item, index) in form.exchangeRateWeb"
          :key="new Date().getTime() + '_' + index"
          :span="12"
        >
          <el-form-item :prop="'exchangeRateWeb.' + index + '.rate'" :rules="[{ required: true, message: $t('必填信息'), trigger: 'blur' }]">
            <span slot="label">
              {{ $t(formatCurrency(item.sourceCurrency)) }}{{ $t('对') }}{{ $t(formatCurrency(item.targetCurrency)) }}{{ $t('汇率') }}
              <el-tooltip :content="$t('使用') + item.placeholder" placement="right">
                <el-button
                  v-if="item.placeholder !== undefined && item.placeholder !== null && item.placeholder !== ''"
                  class="el-icon-document-copy"
                  size="small"
                  type="text"
                  style="color: #1890ff !important;cursor: pointer;"
                  @click="inputPlaceholder(index, item.placeholder)"
                />
              </el-tooltip>
            </span>
            <el-input-number
              v-model="item.rate"
              :max="999999999"
              :min="0.000001"
              :placeholder="item.placeholder"
              :controls="false"
              @change="changeBlurRate($event, item)"
              @blur="changeBlurRate($event, item)"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <div class="area-header">
        <span class="area-header-title">{{ $t('收益主体列表') }}</span>
      </div>
      <el-table :data="form.dealDistributionDetailsList" class="nowrapTable formTable" border>
        <el-table-column :label="$t('序号')" align="center" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('主体名称')" align="center" min-width="222">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('主体名称') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.investorId'" :rules="[{ required: true, message: $t('必填信息'), trigger: ['blur', 'change'] }]">
              <el-select v-model="scope.row.investorId" filterable clearable :placeholder="$t('主体名称')" @change="checkRepeat($event, scope.$index)">
                <el-option
                  v-for="dict in dealDistributionDetailsOption"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="amountDistribution" min-width="130">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('回款总额') }}{{ $t('金额单位') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.amountDistribution'" :rules="[{ required: false, message: $t('必填信息'), trigger: ['blur', 'change'] }]">
              <money v-model="scope.row.amountDistribution" disabled unit="w" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="numberOfSharesBeforeExit" min-width="145">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('退出前股数') }}{{ $t('(万股)') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.numberOfSharesBeforeExit'">
              <money v-model="scope.row.numberOfSharesBeforeExit" unit="w" disabled />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('退出股数') + $t('(万股)')" align="center" prop="withdrawalOfShareCapital" min-width="140">
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.withdrawalOfShareCapital'">
              <money v-model="scope.row.withdrawalOfShareCapital" unit="w" :placeholder="$t('退出股数') + $t('(万股)')" @change="capitalChange($event, scope.$index)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="numberOfShares" min-width="165">
          <template slot="header" slot-scope="{}">
            {{ $t('退出后持股数量') + $t('(万股)') }}
            <el-tooltip :content="$t('项目投资主体中的持股数量-退出股数')" placement="top">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.numberOfShares'">
              <money v-model="scope.row.numberOfShares" unit="w" :placeholder="$t('退出后持股数量')" @change="numberOfSharesChange($event, scope.$index)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="exitShareRatio" min-width="150">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('退出后持股比例(%)') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsList.' + scope.$index + '.exitShareRatio'" :rules="[{required: true, message: $t('必填信息'), trigger: 'blur'}]">
              <Ratio v-model="scope.row.exitShareRatio" :placeholder="$t('退出后持股比例')" @change="exitShareRatioChangeHandle($event, scope.$index)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column v-if="!otherBtnHide" :label="$t('操作')" fixed="right" align="center" min-width="80">
          <template slot-scope="scope">
            <el-button v-hasPermi="['deal:distribution:remove']" type="text" class="el-icon-delete" @click="delHandlerInvestor(scope.$index, scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <div class="tol" style="display: -webkit-box;">
        <el-button v-if="!otherBtnHide" type="primary" icon="el-icon-plus" size="mini" @click="addHandleInvestor">
          {{ $t("添加") }}
        </el-button>
        <div>
          <el-form-item :prop="'calculateShareholding'" class="css-calculate-shareholding" style="margin-top: 2px;">
            <el-checkbox v-model="form.calculateShareholding">{{ $t('审批通过后-退出后持股数量和退出后持股比例更新至投资主体(投资主体持股 = 本次退出后持股)') }}</el-checkbox>
          </el-form-item>
        </div>
      </div>
      <!-- 收益明细 -->
      <div class="area-header" style="margin-top: 20px;">
        <span class="area-header-title">{{ $t('回款明细') }}</span>
      </div>
      <el-table :data="form.dealDistributionDetailsSubList" class="nowrapTable formTable" border>
        <el-table-column :label="$t('序号')" align="center" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('主体名称')" align="center" min-width="222">
          <template slot="header" slot-scope="{}">
            <i style="color: #ff4949;margin-right: 4px;">*</i>
            <span>{{ $t('主体名称') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.investorId'" :rules="dealDistributionDetailsSubListRules.investorId">
              <el-select v-model="scope.row.investorId" filterable clearable :placeholder="$t('主体名称')" @paste.native="copyPaste($event,scope,'investorId')" @change="sumMoneySubDetail(scope.row)">
                <el-option
                  v-for="dict in dealDistributionDetailsSubOption"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="collectionTime" min-width="170">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('预计回款时间') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.collectionTime'">
              <el-date-picker
                v-model="scope.row.collectionTime"
                type="date"
                style="width: 150px"
                :placeholder="$t('预计回款时间')"
                @paste.native="copyPaste($event,scope,'collectionTime')"
              />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('本金') + $t('金额单位')" align="center" prop="amountPrincipal" min-width="130">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('本金') }}{{ $t('金额单位') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.amountPrincipal'">
              <money v-model="scope.row.amountPrincipal" unit="w" :clearable="false" @paste.native="copyPaste($event,scope,'amountPrincipal')" @change="sumMoneySubDetail(scope.row)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('收益') + $t('金额单位')" align="center" prop="amountIncome" min-width="130">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('收益') }}{{ $t('金额单位') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.amountIncome'">
              <money v-model="scope.row.amountIncome" unit="w" :clearable="false" @paste.native="copyPaste($event,scope,'amountIncome')" @change="sumMoneySubDetail(scope.row)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('分红') + $t('金额单位')" align="center" prop="amountBonus" min-width="130">
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.amountBonus'">
              <money v-model="scope.row.amountBonus" unit="w" :clearable="false" @paste.native="copyPaste($event,scope,'amountBonus')" @change="sumMoneySubDetail(scope.row)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('其它') + $t('金额单位')" align="center" prop="amountOthers" min-width="130">
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.amountOthers'">
              <money v-model="scope.row.amountOthers" unit="w" :clearable="false" @paste.native="copyPaste($event,scope,'amountOthers')" @change="sumMoneySubDetail(scope.row)" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('回款总额') + $t('金额单位')" align="center" min-width="130">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('回款总额') }}{{ $t('金额单位') }}</span>
            <el-tooltip :content="$t('不能为0, 可通过修改本金,收益,分红,其他来计算当前值')">
              <i class="el-icon-question" />
            </el-tooltip>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.amountDistribution'" :rules="dealDistributionDetailsSubListRules.amountDistribution">
              <money v-model="scope.row.amountDistribution" disabled unit="w" @paste.native="copyPaste($event,scope,'amountDistribution')" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column :label="$t('备注')" align="center" prop="payeeName" min-width="130">
          <template slot="header" slot-scope="{}">
            <span>{{ $t('备注') }}</span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'dealDistributionDetailsSubList.' + scope.$index + '.payeeName'">
              <el-input v-model="scope.row.payeeName" maxlength="100" :placeholder="$t('备注')" @paste.native="copyPaste($event,scope,'payeeName')" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column v-if="!otherBtnHide" :label="$t('操作')" fixed="right" align="center" min-width="80">
          <template slot-scope="scope">
            <el-button v-hasPermi="['deal:distribution:remove']" type="text" class="el-icon-delete" @click="delHandleDetail(scope.$index, scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <div class="tol" style="display: -webkit-box;">
        <el-button v-if="!otherBtnHide" type="primary" icon="el-icon-plus" size="mini" @click="addHandleDetails">
          {{ $t("添加") }}
        </el-button>
      </div>

      <div v-if="form.actStatus === 'W'">
        <div class="area-header" style="margin-top: 20px;">
          <span class="area-header-title">{{ $t('实际回款明细') }}</span>
        </div>
        <el-table :data="form.dealDistributionPaymentList" border class="nowrapTable formTable">
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('主体名称') }}</span>
            </template>
            <template slot-scope="scope">
              {{ scope.row.investorName }}
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('回款时间') }}</span>
            </template>
            <template slot-scope="scope">
              {{ parseTime(scope.row.collectionTime) }}
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('本金') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              {{ moneyFormat(scope.row.amountPrincipal, 'w') }}
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('收益') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              {{ moneyFormat(scope.row.amountIncome, 'w') }}
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('分红') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              {{ moneyFormat(scope.row.amountBonus, 'w') }}
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('其他') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              {{ moneyFormat(scope.row.amountOthers, 'w') }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('备注')" align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('备注') }}</span>
            </template>
            <template slot-scope="scope">
              {{ scope.row.payeeName }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 附件列表 -->
      <FileTable :list.sync="form.fileList" has-permi="deal:distribution" data-type="deal_distribution" :business-id="autoBusinessId($route.query.id, form)" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <FormBtn ref="formBtn" :bus-data="form" has-permi="deal:distribution" :btn-hide="btnHide" :menu-key="menuKey" />
    </div>
  </div>
</template>

<script>
import {
  saveDealDistribution,
  getDealDistribution,
  getInvestment,
  deleteByIdToSubDetails,
  deleteDetailsById
} from '@/api/deal/distribution/dealDistribution'
import { findProcessEndByDealId } from '@/api/deal/exit/dealExit'
import { getDealBase, getDealName } from '@/api/base/deal/dealBase'
import { getWebRate } from '@/api/deal/investment/dealInvestment'
import { moneyFormat, ruoyiFloat } from '@/utils/ruoyi'
import DealSelect from '@/components/Select/dealSelect'
import { listDataContract } from '@/api/oa/contract/oaContract'
import { listDataContractAndChange } from '@/api/deal/contract/dealContract'

export default {
  components: {
    DealSelect
  },
  data() {
    const checkDetailsMoney = (rule, value, callback) => {
      if (value === undefined || value === '' || value === null) {
        callback(new Error(this.$t('必填信息')))
      } else {
        console.log(value)
        if (value <= 0) {
          callback(new Error(this.$t('不能为0')))
        } else {
          callback()
        }
      }
    }
    return {
      // 菜单标识
      menuKey: 'deal_distribution',
      // 是否隐藏保存按钮
      btnHide: false,
      // 是否隐藏其他按钮
      otherBtnHide: false,
      // 回款类型字典
      distributionTypeOptions: [],
      // 币种字典
      currencyOptions: [],
      // 退出方式字典
      exitModeOptions: [],
      // 项目总股数
      dealTotalShare: undefined,
      form: {
        dealDistributionDetailsList: [],
        dealDistributionDetailsSubList: [],
        // 附件列表
        fileList: []
      },
      dealDistributionDetailsOption: [],
      // 关联退出列表
      exitList: [],
      isShowJoinExit: false,
      // 合同下拉
      contractOptions: [],
      // 表单校验
      rules: {
        dealId: { required: true, message: this.$t('必填信息'), trigger: 'blur' },
        quitStatus: { required: true, message: this.$t('必填信息'), trigger: 'blur' },
        registeredCapita: { required: true, message: this.$t('必填信息'), trigger: 'blur' },
        distributionType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        distributionDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        amountPrincipal: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        amountIncome: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        amountDistribution: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        currency: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        actTitle: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
      },
      dealDistributionDetailsSubListRules: {
        investorId: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        amountDistribution: [{ required: true, validator: checkDetailsMoney, trigger: ['change', 'blur'] }]
      },
      // 遮罩层
      loading: false,
      tempDealDistributionDetailsList: [],
      // 操作按钮默认不展示
      buttonShow: true,
      dealBaseData: undefined,
      dealDistributionDetailsSubOption: []
      // unwatch: undefined
    }
  },
  watch: {
    // 侦听收益主体列表数据
    'form.dealDistributionDetailsSubList': {
      handler(val) {
        this.form.amountPrincipal = 0
        this.form.amountIncome = 0
        this.form.amountOthers = 0
        this.form.amountBonus = 0
        this.form.amountDistribution = 0
        if (val != null) {
          val.forEach((e) => {
            this.form.amountPrincipal += this.formatNumber(e.amountPrincipal)
            this.form.amountIncome += this.formatNumber(e.amountIncome)
            this.form.amountOthers += this.formatNumber(e.amountOthers)
            this.form.amountBonus += this.formatNumber(e.amountBonus)
            this.form.amountDistribution += this.formatNumber(e.amountDistribution)
          })
        }
      },
      deep: true,
      immediate: true
    },
    'form.dealDistributionDetailsList': {
      handler(val) {
        if (val) {
          this.form.numberOfShares = 0
          this.form.exitShareRatio = 0
          val.forEach(e => {
            this.form.exitShareRatio += this.formatNumber(e.exitShareRatio)
            this.form.numberOfShares += this.formatNumber(e.numberOfShares)
          })
        }
      },
      deep: true,
      immediate: true
    },
    'form.currency': {
      handler(val) {
        if (val) {
          this.setRateByInvestor()
        }
      }
    }
  },
  created() {
    this.getDicts('distribution_mode').then(response => {
      this.distributionTypeOptions = response.data
    })
    this.getDicts('currency').then(response => {
      this.currencyOptions = response.data
    })
    this.getDicts('deal_exit_strategy').then(response => {
      this.exitModeOptions = response.data
    })
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    async init(data) {
      this.loading = true
      this.dealDistributionDetailsOption = []
      this.contractOptions = []
      if (data != null && data.id !== undefined) {
        getDealDistribution(data.id).then(response => {
          this.form = response.data
          // 获取项目总股数
          getDealBase(this.form.dealId).then(res => {
            this.dealTotalShare = res.data && res.data.dealBaseEquity && res.data.dealBaseEquity.totalShare && res.data.dealBaseEquity ? res.data.dealBaseEquity.totalShare : 0
            this.dealBaseData = res.data
            this.form.exchangeRateWeb = JSON.parse((this.form.exchangeRate === undefined || this.form.exchangeRate === null || this.form.exchangeRate === '') ? '[]' : this.form.exchangeRate)
            if (this.form.exchangeRateWeb.length === 0) {
              this.getInvestorList()
            } else {
              this.getInvestorListToCurrency()
            }
            this.$forceUpdate()
          })
          findProcessEndByDealId(this.form.dealId).then(response => {
            this.exitList = response.data
          })
          getInvestment(this.form.dealId).then(response => {
            if (response.data !== undefined && response.data !== null) {
              response.data.forEach(item => {
                this.dealDistributionDetailsOption.push({ id: item.investorId, name: item.investorName, currency: item.currency })
              })
            }
            this.autoDetailsSubOption()
          })
          this.contractDict()
          // 实际付款请款只显示有时间的数据
          this.initDataPayment()
          this.loading = false
        })
      } else {
        this.reset()
        this.contractDict()
        await this.addInitLoad()
        if (this.$route.query.id) {
          this.getBaseInfo(this.$route.query.id)
        }
        this.loading = false
      }
    },
    copyPaste(e, scope, key) {
      e.preventDefault()
      e.stopPropagation()

      var index = scope.$index
      var fields = ['investorId', 'collectionTime', 'amountPrincipal', 'amountIncome', 'amountBonus', 'amountOthers', 'payeeName']
      var clipData = e.clipboardData.getData('text')
      var rows = clipData.split('\r\n')
      var arr = []

      for (let i = 0; i < rows.length; i++) {
        if (rows[i]) {
          var columns = rows[i].split('\t')
          arr.push(columns)
        }
      }

      console.log(fields)

      var currentIndex = fields.findIndex(item => item === key)
      var fieldsIndex = []

      if (currentIndex || currentIndex === 0) {
        fieldsIndex = fields.splice(currentIndex, fields.length)
      }

      if (arr.length === 1) {
        // 一行
        arr[0].forEach((column, i) => {
          fieldsIndex.forEach((j, n) => {
            if (column && i === n) {
              if (j === 'investorId') {
                var dict = this.dealDistributionDetailsSubOption.find(item => item.name === column)
                console.log(dict, dict ? dict.id : '', dict.id)
                this.form.dealDistributionDetailsSubList[index][j] = dict ? dict.id : ''
              } else if (j === 'collectionTime') {
                this.form.dealDistributionDetailsSubList[index][j] = this.convertExcelDateToFormattedDate(column)
              } else if (j === 'payeeName') {
                this.form.dealDistributionDetailsSubList[index][j] = column
              } else {
                this.form.dealDistributionDetailsSubList[index][j] = isNaN(column) ? '' : column
              }
            }
          })
        })
      } else if (arr.length > 1) {
        var rowsArr = []
        arr.forEach(data => {
          var obj = {}
          data.forEach((cData, i) => {
            fieldsIndex.forEach((j, n) => {
              if (cData && i === n) {
                // obj[j] = isNaN(moneyFormat(cData)) ? '' : moneyFormat(cData)

                if (j === 'investorId') {
                  var dict = this.dealDistributionDetailsSubOption.find(item => item.name === cData)
                  console.log(dict, dict ? dict.id : '', dict.id)
                  obj[j] = dict ? dict.id : ''
                } else if (j === 'collectionTime') {
                  obj[j] = this.convertExcelDateToFormattedDate(cData)
                } else if (j === 'payeeName') {
                  obj[j] = cData
                } else {
                  obj[j] = isNaN(cData) ? '' : cData
                }
              }
            })
          })
          rowsArr.push(obj)
        })

        console.log(rowsArr)

        rowsArr.forEach((item, idx) => {
          for (const key in item) {
            this.form.dealDistributionDetailsSubList[index + idx][key] = item[key]
          }
        })
      }
      this.$forceUpdate()
    },
    // 格式化excel中的日期
    convertExcelDateToFormattedDate(excelDate) {
      // 将Excel日期字符串分割为年、月和日
      const parts = excelDate.split('/')

      // 确保月份和日期有两位数字
      const year = parts[0]
      const month = String(parts[1]).padStart(2, '0')
      const day = String(parts[2]).padStart(2, '0')

      // 格式化为yyyy-mm-dd
      return `${year}-${month}-${day}`
    },
    getBaseInfo(dealId) {
      // 获取基本信息下的注册资本 totalShare
      getDealBase(dealId).then(response => {
        this.dealBaseData = response.data
        if (this.isNotEmpty(response.data) && this.isNotEmpty(response.data.currency) && !this.isNotEmpty(this.form.currency)) {
          this.form.currency = response.data.currency
        }
        if (response.data && response.data.dealBaseEquity && response.data.dealBaseEquity.totalShare !== undefined && response.data.dealBaseEquity.totalShare !== null && response.data.dealBaseEquity.totalShare !== '') {
          this.form.registeredCapita = response.data.dealBaseEquity.totalShare
        }
        this.setRateByInvestor()
        this.autoDetailsSubOption()
        this.loading = false
      })
    },
    initDataPayment() {
      var temp = []
      this.form.dealDistributionPaymentList && this.form.dealDistributionPaymentList.forEach(item => {
        if (item.collectionTime !== undefined && item.collectionTime !== null && item.collectionTime !== '') {
          temp.push(item)
        }
      })
      this.$nextTick(() => {
        this.form.dealDistributionPaymentList = temp
      })
    },
    // 根据出资主体列表 动态添加汇率
    setRateByInvestor() {
      this.settingHoldShareCurrency()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.$route.query.id,
        distributionType: undefined,
        distributionDate: undefined,
        amountPrincipal: undefined,
        amountIncome: undefined,
        amountBonus: undefined,
        amountOthers: undefined,
        amountDistribution: undefined,
        registeredCapita: undefined,
        quitStatus: undefined,
        currency: '',
        calculateShareholding: true,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined,
        delFlag: undefined,
        joinExit: undefined,
        relatedContracts: undefined,
        exitShareRatio: undefined,
        numberOfShares: undefined,
        dealDistributionDetailsList: [], // 收益主体列表
        dealDistributionDetailsSubList: [],
        fileList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      if (this.$parent.$parent.reset !== undefined) {
        this.$parent.$parent.reset()
      }
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm: function(type) {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate(valid => {
          if (this.isEmpty(this.form.dealDistributionDetailsSubList)) {
            this.msgError(this.$t('请录入回款明细'))
            valid = false
          }
          // 验证数据
          if (valid) {
            this.form.exchangeRate = JSON.stringify(this.form.exchangeRateWeb)
            if (type === 'process' && (this.form.quitStatus === 'QBTC')) {
              var _this = this
              this.$confirm(this.$t('当前状态为[全部退出], 审批结束后当前项目则跳转至退出阶段, 是否继续?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              }).then(() => {
                _this.submitFormSave(type, resolve, reject)
              })
            } else {
              this.submitFormSave(type, resolve, reject)
            }
          } else {
            this.locationError(document)
            reject()
          }
        })
      })
    },
    submitFormSave(type, resolve, reject) {
      // 弹出遮罩层
      this.loading = true
      // 保存数据
      saveDealDistribution(this.form).then(response => {
        if (response.code === 200) {
          // 点击的按钮是保存并启动流程
          if (type === 'process') {
            // 设置数据id方式启动流程后取消并再次启动会创建多条记录
            this.form = response.data
            this.form.exchangeRateWeb = JSON.parse((this.form.exchangeRate === undefined || this.form.exchangeRate === null || this.form.exchangeRate === '') ? '[]' : this.form.exchangeRate)
            // 启动流程
            this.startProcess(response.data)
            // 点击的仅保存
          } else {
            this.msgSuccess(this.$t('保存成功'))
            // 关闭form页面
            this.closeForm()
          }
          resolve(response.data.id)
        } else {
          this.msgError(response.msg)
          this.loading = false
          reject(response)
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 启动流程
    startProcess: async function(data) {
      var dealName = await getDealName(this.form.dealId)
      this.loading = false
      // 启动流程时候传入的参数
      const processData = {}
      // 待办标题
      processData.title = '「' + dealName + '」' + ':' + this.form.actTitle + '(' + moneyFormat(data.amountDistribution, 'w') + ')'
      // 业务表名
      processData.dataTable = 'deal_distribution'
      // 业务ID
      processData.dataId = data.id
      // 业务表单地址(待办页面需要打开的页面)
      processData.formPath = '@/views/deal/distribution/dealDistributionForm'
      processData.viewPath = '@/views/deal/distribution/dealDistributionView'
      // 菜单标识(根据菜单标识判断的走哪个流程)
      processData.menuKey = this.menuKey
      this.startProcessByMenu(processData, () => {
        this.form.actStatus = 'D'
        this.msgSuccess(this.$t('数据保存成功,流程启动成功'))
        this.closeForm()
      })
    },
    exitModeFormat(row) {
      return this.selectDictLabel(this.exitModeOptions, row.exitStrategy)
    },
    distributionTypeFormat(distributionType) {
      return this.selectDictLabel(this.distributionTypeOptions, distributionType)
    },
    addInitLoad() {
      if (this.form.dealId) {
        findProcessEndByDealId(this.form.dealId).then(response => {
          this.exitList = response.data
        })
        // 获取项目总股数
        getDealBase(this.form.dealId).then(res => {
          this.dealTotalShare = res.data.dealBaseEquity.totalShare && res.data.dealBaseEquity ? res.data.dealBaseEquity.totalShare : 0
        })
        this.getInvestorList()
      } else {
        this.exitList = []
        this.dealTotalShare = undefined
        this.form.dealDistributionDetailsList = []
      }
    },
    /**
     * 获取主体信息, 新增时为TRUE. 给子表数据赋值. 修改时为FALSE. 查出来temp. 用于后面的计算
     * @param flag
     */
    getInvestorList() {
      if (this.form.id === undefined || this.form.id === null || this.form.id === '') {
        getInvestment(this.form.dealId).then(response => {
          if (response.data !== undefined && response.data !== null) {
            this.form.dealDistributionDetailsList = response.data
            response.data.forEach(item => {
              item.numberOfSharesBeforeExit = item.numberOfShares
              this.dealDistributionDetailsOption.push({
                id: item.investorId,
                name: item.investorName,
                numberOfSharesBeforeExit: item.numberOfShares,
                currency: item.currency
              })
            })
          }
          this.tempDealDistributionDetailsList = []
          if (response.data !== null) {
            response.data.forEach(item => {
              this.tempDealDistributionDetailsList.push({
                investorName: item.investorName,
                investorId: item.investId,
                numberOfShares: item.numberOfShares,
                currency: item.currency
              })
            })
          }
        })
      } else {
        if (this.form.exchangeRateWeb.length === 0 && this.form.dealDistributionDetailsList !== null) {
          getInvestment(this.form.dealId).then(response => {
            if (response.data !== undefined && response.data !== null) {
              response.data.forEach(item => {
                this.dealDistributionDetailsOption.push({
                  id: item.investorId,
                  name: item.investorName,
                  numberOfSharesBeforeExit: item.numberOfShares,
                  currency: item.currency
                })
              })
              this.form.dealDistributionDetailsList.forEach(item => {
                const find = this.dealDistributionDetailsOption.find(obj => obj.id === item.investorId)
                if (find) {
                  item.currency = find.currency
                }
              })
              this.setRateByInvestor()
            }
          })
        }
      }
    },
    getInvestorListToCurrency() {
      getInvestment(this.form.dealId).then(response => {
        if (response.data !== undefined && response.data !== null) {
          response.data.forEach(item => {
            this.dealDistributionDetailsOption.push({
              id: item.investorId,
              name: item.investorName,
              numberOfSharesBeforeExit: item.numberOfShares,
              currency: item.currency
            })
          })
          this.form.dealDistributionDetailsList.forEach(item => {
            const find = this.dealDistributionDetailsOption.find(obj => obj.id === item.investorId)
            if (find) {
              item.currency = find.currency
            }
          })
        }
        this.$forceUpdate()
      })
    },
    // 合同
    contractDict() {
      var tempDealId = this.form.dealId
      if (tempDealId === '' || tempDealId === undefined || tempDealId === null) {
        tempDealId = this.$route.query.id
      }
      const params = {
        dealId: tempDealId
      }
      listDataContract(params).then(response => {
        const temp = []
        response.data.forEach(item => {
          this.contractOptions.push(item)
          temp.push(item.id)
        })
        if (!temp.includes(this.form.contractId)) {
          listDataContractAndChange(this.form.contractId).then(response => {
            const data = response.data
            if (data !== null) {
              this.contractOptions.push({ id: data.id, name: data.name, type: data.type, contractPayables: data.contractPayables })
            }
          })
        }
      })
    },
    dealSelectChangeHandle(val) {
      this.getBaseInfo(val)
      this.form.dealId = val
      this.addInitLoad()
    },
    // 持股数量change
    numberOfSharesChange(val, index) {
      // const distribution = this.form.dealDistributionDetailsList[index]
      // if (this.dealTotalShare && distribution.numberOfShares) {
      //   this.$set(this.form.dealDistributionDetailsList[index], 'exitShareRatio', val / this.form.registeredCapita * 100)
      // }
      console.log(val, index)
    },
    exitShareRatioChangeHandle(val, index) {
      // this.$nextTick(() => {
      //   var ratio = 0
      //   this.form.dealDistributionDetailsList.forEach((ele) => {
      //     ratio += ele.exitShareRatio
      //   })
      //   if (ratio > 100) {
      //     this.$set(this.form.dealDistributionDetailsList[index], 'exitShareRatio', 0)
      //   }
      // })
      console.log(val, index)
    },
    // 退出股数注册资本变化时 公式: 1. 退出后持股数量: 项目投资主体中的持股数量 - 退出股数
    capitalChange(val, index) {
      const rowInvestName = this.form.dealDistributionDetailsList[index].investorName
      // 回款后持股数量
      var dealNumber = 0
      const object = this.tempDealDistributionDetailsList.find(obj => obj.investorName === rowInvestName)
      if (object) {
        dealNumber = this.formatNumber(object.numberOfShares) - this.formatNumber(val)
      }
      if (dealNumber < 0) {
        dealNumber = 0
      }
      this.form.dealDistributionDetailsList[index].numberOfShares = dealNumber
      this.numberOfSharesChange(dealNumber, index)
    },
    // 检查子表主体是否重复
    checkRepeat(val, rowIndex) {
      console.log(val)
      var details = this.form.dealDistributionDetailsList
      if (details !== undefined && details !== null && details !== '') {
        var flag = true
        var count = 0
        details.forEach((item, index) => {
          if (item.investorId === val) {
            if (count > 0) {
              details[index].investorId = undefined
              this.msgError(this.$t('不能重复添加!'))
              flag = false
            }
            count++
          }
        })
        const object = this.dealDistributionDetailsOption.find(obj => obj.id === val)
        if (object !== undefined && flag) {
          this.form.dealDistributionDetailsList[rowIndex].numberOfSharesBeforeExit = object.numberOfSharesBeforeExit
        }
      }
      // 自动完善收益明细的主体 option
      this.autoDetailsSubOption()
      this.settingHoldShareCurrency()
    },
    /**
     * 自动完善收益明细的主体的下拉. 及下拉中的数据
     */
    autoDetailsSubOption() {
      this.dealDistributionDetailsSubOption = []
      var tempInvestorId = []
      // 获取下拉中都应该有啥
      this.form.dealDistributionDetailsList && this.form.dealDistributionDetailsList.forEach(item => {
        const object = this.dealDistributionDetailsOption.find(obj => obj.id === item.investorId)
        if (object) {
          tempInvestorId.push(object.id)
          this.dealDistributionDetailsSubOption.push(object)
        }
      })
      // 如果收益主体进行了删除操作了. 那么就进行对收益明细里的主体进行置空操作
      this.form.dealDistributionDetailsSubList && this.form.dealDistributionDetailsSubList.forEach(item => {
        if (!tempInvestorId.includes(item.investorId)) {
          item.investorId = undefined
          this.$forceUpdate()
        }
      })
    },
    // 配置投资主体股东的币种汇率
    settingHoldShareCurrency() {
      var parseRate = []
      var result = []
      if (this.form.exchangeRateWeb !== undefined && this.form.exchangeRateWeb !== '' && this.form.exchangeRateWeb !== null) {
        parseRate = this.form.exchangeRateWeb
      }
      var tempParseRate = JSON.parse(JSON.stringify(parseRate))
      var temp = []
      this.form.dealDistributionDetailsList.forEach(detail => {
        var object = this.dealDistributionDetailsOption.find(obj => obj.id === detail.investorId)
        if (object) {
          if (object.currency !== null && object.currency !== this.form.currency) {
            const t2 = tempParseRate.find(obj => obj.sourceCurrency === object.currency)
            if (t2) {
              temp.push({ 'sourceCurrency': t2.sourceCurrency, 'targetCurrency': this.form.currency, 'rate': t2.rate })
            } else {
              temp.push({ 'sourceCurrency': object.currency, 'targetCurrency': this.form.currency, 'rate': undefined })
            }
          }
        }
      })
      result = temp
      // 确保汇率中有当前项目币种 - 如果项目比重不为空, 并且表单币种不为空,  并且两个币种不相等. 那么就添加上该表单币种对当前项目币种之间的汇率
      var currencyList = []
      result.forEach(item => {
        currencyList.push(item.sourceCurrency)
      })
      if (this.dealBaseData !== null && this.isNotEmpty(this.dealBaseData) && this.isNotEmpty(this.form.currency) && this.form.currency !== this.dealBaseData.currency) {
        if (!currencyList.includes(this.dealBaseData.currency)) {
          result.push({
            sourceCurrency: this.dealBaseData.currency,
            targetCurrency: this.form.currency,
            rate: undefined
          })
        }
      }
      console.log(result)
      // 数组中去除重复对象
      var resultArr = []
      var resultTemp = []
      result && result.forEach(item => {
        var temp = item.rate + '-' + item.placeholder + '-' + item.sourceCurrency + '-' + item.targetCurrency
        if (!resultTemp.includes(temp)) {
          resultArr.push(item)
          resultTemp.push(temp)
        }
      })
      console.log(resultArr)
      this.$set(this.form, 'exchangeRateWeb', resultArr)
      this.$nextTick(() => {
        this.getWebRate()
        this.$forceUpdate()
      })
    },
    getWebRate() {
      this.form.exchangeRateWeb.forEach((item, index) => {
        if (item !== undefined && item.targetCurrency !== undefined && item.sourceCurrency !== undefined) {
          getWebRate(item.targetCurrency, item.sourceCurrency, this.form.distributionDate).then(response => {
            if (response.data !== '' && response.data !== null) {
              item.placeholder = response.data
              this.$set(this.form.exchangeRateWeb[index], 'placeholder', this.$t('近期汇率参考') + ': ' + response.data)
              this.$forceUpdate()
            }
          })
        }
      })
    },
    inputPlaceholder(index, val) {
      if (val !== undefined && val !== null && val !== '') {
        val = val.replaceAll('近期汇率参考', '').replaceAll(':', '').trim()
        this.$set(this.form.exchangeRateWeb[index], 'rate', parseFloat(val))
        this.$forceUpdate()
      }
    },
    // 删除时 调整汇率
    delSetHoldShareCurrency() {
      var parseRate = []
      if (this.form.exchangeRateWeb !== undefined && this.form.exchangeRateWeb !== '' && this.form.exchangeRateWeb !== null) {
        parseRate = this.form.exchangeRateWeb
      }
      var temp = JSON.parse(JSON.stringify(parseRate))
      var currentCurrency = []
      this.form.dealDistributionDetailsList.forEach(detail => {
        if (detail.investorId) {
          var object = this.dealDistributionDetailsOption.find(obj => obj.id === detail.investorId)
          if (object) {
            currentCurrency.push(object.currency)
          }
        }
      })
      if (currentCurrency.length <= 0) {
        temp = []
      } else {
        temp.forEach(item => {
          if (!currentCurrency.includes(item.currency)) {
            temp.splice(temp.indexOf(item), 1)
          }
        })
      }
      this.form.exchangeRateWeb = temp
    },
    addHandleInvestor() {
      const row = {
        id: undefined,
        investorId: undefined,
        exitShareRatio: 0,
        amountDistribution: 0,
        numberOfSharesBeforeExit: 0,
        withdrawalOfShareCapital: 0,
        numberOfShares: 0
      }
      if (!(this.form.dealDistributionDetailsList instanceof Array)) {
        this.$set(this.form, 'dealDistributionDetailsList', [])
      }
      this.$nextTick(() => {
        this.form.dealDistributionDetailsList.push(row)
      })
    },
    delHandlerInvestor(index, row) {
      if (row.id !== undefined && row.id !== null && row.id !== '') {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        })
          .then(function() {
            return deleteDetailsById(row.id)
          }).then(() => {
          this.form.dealDistributionDetailsList.splice(index, 1)
          return this.msgSuccess(this.$t('删除成功'))
        })
          .catch(function() {
          })
      } else {
        this.form.dealDistributionDetailsList.splice(index, 1)
        this.autoDetailsSubOption()
        this.settingHoldShareCurrency()
      }
    },
    sumMoneySubDetail(row) {
      var tempMoney = 0
      var tempInvestorId = row.investorId
      this.form.dealDistributionDetailsSubList && this.form.dealDistributionDetailsSubList.forEach(item => {
        if (item.investorId === tempInvestorId) {
          item.amountDistribution = this.formatNumber(item.amountPrincipal) + this.formatNumber(item.amountIncome) + this.formatNumber(item.amountBonus) + this.formatNumber(item.amountOthers)
          tempMoney += item.amountDistribution
        }
      })
      // 合并到 受益主体列表中
      console.log('合并到 受益主体列表中')
      if (tempMoney && tempInvestorId) {
        this.form.dealDistributionDetailsList && this.form.dealDistributionDetailsList.forEach((item, index) => {
          if (item.investorId === tempInvestorId) {
            this.$set(this.form.dealDistributionDetailsList[index], 'amountDistribution', tempMoney)
          }
        })
      }
    },
    addHandleDetails() {
      const row = {
        id: undefined,
        investorId: undefined,
        amountPrincipal: undefined,
        amountIncome: undefined,
        amountBonus: undefined,
        amountOthers: undefined,
        amountDistribution: undefined,
        collectionTime: undefined,
        payeeName: undefined
      }
      if (!(this.form.dealDistributionDetailsSubList instanceof Array)) {
        this.$set(this.form, 'dealDistributionDetailsSubList', [])
      }
      this.$nextTick(() => {
        this.form.dealDistributionDetailsSubList.push(row)
      })
    },
    delHandleDetail(index, row) {
      const _this = this
      const id = row.id
      if (id !== undefined && id !== '' && id != null) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        })
          .then(function() {
            return deleteByIdToSubDetails(id)
          }).then(() => {
          _this.form.dealDistributionDetailsSubList.splice(index, 1)
          return _this.msgSuccess(this.$t('删除成功'))
        })
          .catch(function() {
          })
      } else {
        _this.form.dealDistributionDetailsSubList.splice(index, 1)
      }
    },
    isNotEmpty(val) {
      return !(val === undefined || val === null || val === '')
    },
    formatNumber(val) {
      if (val === undefined || val === null || val === '' || isNaN(parseFloat(val))) {
        return 0
      }
      return ruoyiFloat().formatNum(parseFloat(val))
    },
    formatCurrency(val) {
      const currency = this.currencyOptions.find(obj => obj.dictValue === val)
      if (currency) {
        return currency.dictLabel
      }
      return val
    },
    changeBlurRate(val, item) {
      if (val === undefined || val === '' || val === null) {
        val = 0
      }
      if (!isNaN(val)) {
        const index = this.form.exchangeRateWeb.findIndex(obj => (obj.sourceCurrency === item.sourceCurrency && obj.targetCurrency === item.targetCurrency))
        this.$nextTick(() => {
          this.form.exchangeRateWeb[index].rate = (val === 0 ? undefined : val)
          this.$forceUpdate()
        })
      }
    }
  }
}
</script>
<style scoped>
/deep/ .css-calculate-shareholding .el-form-item__content {
  margin-left: 20px !important;
}
</style>
